<!DOCTYPE html>

<html lang="en">
<head>
	<meta charset="utf-8">
	<title>najaxjs Source: default/history.static.js</title>

	<!--[if lt IE 9]>
	<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
	<![endif]-->
	<link type="text/css" rel="stylesheet" href="styles/sunlight.default.css">

	<link type="text/css" rel="stylesheet" href="styles/site.yeti.css">

</head>

<body>

<div class="navbar navbar-default navbar-fixed-top navbar-inverse">
<div class="container">
	<div class="navbar-header">
		<a class="navbar-brand" href="index.html">najaxjs</a>
		<button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#topNavigation">
			<span class="icon-bar"></span>
			<span class="icon-bar"></span>
			<span class="icon-bar"></span>
        </button>
	</div>
	<div class="navbar-collapse collapse" id="topNavigation">
		<ul class="nav navbar-nav">
			
			<li class="dropdown">
				<a href="namespaces.list.html" class="dropdown-toggle" data-toggle="dropdown">Namespaces<b class="caret"></b></a>
				<ul class="dropdown-menu ">
					<li><a href="$najax.html">$najax</a></li><li><a href="$najax.define.html">$najax.define</a></li><li><a href="$najax.history.html">$najax.history</a></li><li><a href="$najax@class.html">$najax@class</a></li><li><a href="$najax@ex.html">$najax@ex</a></li><li><a href="$najax@helper.html">$najax@helper</a></li><li><a href="$najax@read.html">$najax@read</a></li><li><a href="$najax@rlk.html">$najax@rlk</a></li>
				</ul>
			</li>
			
			<li class="dropdown">
				<a href="classes.list.html" class="dropdown-toggle" data-toggle="dropdown">Classes<b class="caret"></b></a>
				<ul class="dropdown-menu ">
					<li><a href="Linker.html">Linker</a></li><li><a href="Nx.html">Nx</a></li><li><a href="Pager.html">Pager</a></li><li><a href="Reflector.html">Reflector</a></li><li><a href="Relay.html">Relay</a></li><li><a href="RESTful.html">RESTful</a></li><li><a href="Singular.html">Singular</a></li><li><a href="Tx.html">Tx</a></li>
				</ul>
			</li>
			
			<li class="dropdown">
				<a href="tutorials.list.html" class="dropdown-toggle" data-toggle="dropdown">Tutorials<b class="caret"></b></a>
				<ul class="dropdown-menu ">
					<li><a href="tutorial-demo-ui-ajax.html">demo-ui-ajax</a></li><li><a href="tutorial-najax-class.html">najax-class</a></li><li><a href="tutorial-najax-ex.html">najax-ex</a></li><li><a href="tutorial-najax-helper.html">najax-helper</a></li><li><a href="tutorial-najax-read.html">najax-read</a></li><li><a href="tutorial-relaylinker.html">relaylinker</a></li><li><a href="tutorial-rlk-standalone.html">rlk-standalone</a></li><li><a href="tutorial-static-history.html">static-history</a></li><li><a href="tutorial-static-najax-micro.html">static-najax-micro</a></li><li><a href="tutorial-static-najax.html">static-najax</a></li>
				</ul>
			</li>
			
			<li class="dropdown">
				<a href="global.html" class="dropdown-toggle" data-toggle="dropdown">Global<b class="caret"></b></a>
				<ul class="dropdown-menu ">
					<li><a href="global.html">Global</a></li>
				</ul>
			</li>
			
		</ul>
		<div class="col-sm-3 col-md-3">
            <form class="navbar-form" role="search">
                <div class="input-group">
                    <input type="text" class="form-control" placeholder="Search" name="q" id="search-input">
                    <div class="input-group-btn">
                        <button class="btn btn-default" id="search-submit"><i class="glyphicon glyphicon-search"></i></button>
                    </div>
                </div>
            </form>
        </div>
	</div>

</div>
</div>


<div class="container" id="toc-content">
<div class="row">

	
	<div class="col-md-12">
	
		<div id="main">
			

		<h1 class="page-title">Source: default/history.static.js</h1>
    
<section>
    <article>
        <pre
            class="sunlight-highlight-javascript linenums">'use strict';

/**
 * Support history push and replace, listen.
 *
 * &lt;b>&lt;i>Note! Not included in najax-tiny.js.&lt;/i>&lt;/b>&lt;br>
 *
 * | Method | Default ver | Tiny ver |
 * |:---|:---:|:---:|
 * | All methods | Yes | - |
 *
 * @namespace $najax.history
 *
 * @tutorial static-history
 *
 * @example
 * //push
 * $najax.history.push('?v=1');
 * $najax.history.push('?v=1', null, 'abc');
 * $najax.history.pushQuery();
 *
 * //replace
 * $najax.history.replace('?v=1');
 * $najax.history.replace('?v=1', null, 'abc', {data: {v: 2}});
 * $najax.history.replaceQuery('abc', {v: 2});
 *
 * //listen
 * $najax.history.listen(function(e, id, vs, title){ ... });
 *
 * //init
 * $najax.history.replaceListen(function(e, id, vs, title){ ... });
 */
njx.history = {};

/**
 * @ignore
 */
var hsRpl = false;
var hsLtn = false;


/**
 * Push new page's url and title, values. Recommend to use this method with &lt;i>$najax.history.listen&lt;/i>.
 * @function push
 * @memberof $najax.history
 *
 * @param {string} url URL.
 * @param {string|integer} [id=null] Page's id.
 * @param {string} [title=null] Title.
 * @param {assoc} [opt] Options.
 * @param {assoc} [opt.data=null] Passed values.
 * @param {assoc} [opt.store=true] Store first page's data by &lt;i>$najax.history.replace&lt;/i>.
 * @param {function} [opt.legacy=null] Legacy browser's behaviors. &lt;code>Ex: function(url, title, vs){location.href = url;}&lt;/code>
 *
 * @see $najax.history.pushQuery
 *
 * @tutorial static-history
 *
 * @example
 * $najax.history.push('?v=1');
 * $najax.history.push('?v=1', id, 'abc', {data: {v: 2}});
 * $najax.history.push('?v=1', null, null, {legacy: function(url, id, title, vs){ ... } });
 */
njx.history.push = function(url, id, title, opt){
	opt = ext({data:null, store: true, legacy: null}, opt);

	id = (id !== undefined)?id:null;
	title = (title !== undefined)?title:null;

	if (history.pushState){
		if (opt.store &amp;&amp; !hsRpl){
			njx.history.replace();
		}

		history.pushState({id: id, title: title, data: opt.data}, title, url);
	}else{
		if (opt.legacy){
			opt.legacy.call(null, url, id, title, opt.data);
		}
	}
};

/**
 * Push new page's url and title, values. Support query-string. Recommend to use this with &lt;i>$najax.history.listen&lt;/i>.
 * @function pushQuery
 * @memberof $najax.history
 *
 * @param {string|integer} [id=null] Page's id.
 * @param {string} [title=null] Title. If null, set now title.
 * @param {assoc} [vs=null] Passed values. URL's query-string values is overrided by this values.
 * @param {assoc} [opt] Options. $najax.history.push options.
 *
 * @see $najax.history.pushQuery
 *
 * @tutorial static-history
 *
 * @example
 * $najax.history.pushQuery();
 * $najax.history.pushQuery(id, 'abc', vs, {data: {v: 2}});
 * $najax.history.pushQuery(null, 'abc', null, {title: false});
 */
njx.history.pushQuery = function(id, title, vs, opt){
	var u = njx.url(location.href, vs);

	njx.history.push(u, id, title, vs, opt);
};

/**
 * Replace now page's url and title, values.
 * @function replace
 * @memberof $najax.history
 *
 * @param {string} [url] URL. If null, prepare now url.
 * @param {string|integer} [id=null] Page's id.
 * @param {string} [title=null] Title. If null, set now title.
 * @param {assoc} [opt] Options.
 * @param {assoc} [opt.data=null] Passed values.
 * @param {function} [opt.legacy=null] Legacy browser's behaviors. &lt;code>Ex: function(url, title, vs){location.replace = url;}&lt;/code>
 *
 * @see $najax.history.replaceQuery
 *
 * @tutorial static-history
 *
 * @example
 * $najax.history.replace('?v=1');
 * $najax.history.replace('?v=1', id, 'abc', {data: {v: 2}});
 * $najax.history.replace('?v=1', null, null, {legacy: function(url, id, title, vs){ ... } });
 */
njx.history.replace = function(url, id, title, opt){
	opt = ext({data:null, legacy: null}, opt);

	hsRpl = true;

	if (url == null){
		url = location.href;
	}

	if (title == null){
		title = document.title;
	}

	if (history.pushState){
		history.replaceState({id: id, title: title, data: opt.data}, title, url);
	}else{
		if (opt.legacy){
			opt.legacy.call(null, url, id, title, opt.data);
		}
	}
};

/**
 * Replace now page's url and title, values. Support query-string.
 * @function replaceQuery
 * @memberof $najax.history
 *
 * @param {string|integer} [id=null] Page's id.
 * @param {string} [title=null] Title. If null, set now title.
 * @param {assoc} [vs=null] Passed values. URL's query-string values is overrided by this values.
 * @param {assoc} [opt] Options. $najax.history.replace options.
 *
 * @see $najax.history.replace
 *
 * @tutorial static-history
 *
 * @example
 * $najax.history.replaceQuery();
 * $najax.history.replaceQuery(id, 'abc', vs, {data: {v: 2}});
 * $najax.history.replaceQuery(null, 'abc', null, {title: false});
 */
njx.history.replaceQuery = function(id, title, vs, opt){
	var u = njx.url(location.href, vs);

	njx.history.replace(u, id, title, vs, opt);
};

/**
 * Listen to event of browser's back and prev.
 * @function listen
 * @memberof $najax.history
 *
 * @param {function} fn Callback function. &lt;code>function(e:event, title:string, vs:assoc){ ... }&lt;/code>
 * @param {assoc} [opt] Options.
 * @param {boolean} [opt.title=true] Change title automatically.
 *
 * @tutorial static-history
 *
 * @example
 * $najax.history.listen(function(e, id, title, data){ ... });
 */
njx.history.listen = function(fn, opt){
	opt = ext({title: true}, opt);

	hsLtn = true;

	if (history.pushState){
		window.onpopstate = function(e){
			var id=null, title=null, data=null;

			if (e.state){
				id = e.state.id || null;
				title = e.state.title || null;
				data = e.state.data || null;
			}

			if (fn){
				fn.call(null, e, id, title, data);
			}

			if (opt.title &amp;&amp; title != null){
				document.title = title;
			}
		};
	}
};

/**
 * Replace &amp; replace now.
 * @function init
 * @memberof $najax.history
 *
 * @param {function} fn Callback function. &lt;code>function(e:event, title:string, vs:assoc){ ... }&lt;/code>
 * @param {string|integer} [id=null] Page's id.
 * @param {string} [title=null] Title.
 * @param {assoc} [opt] Options. &lt;i>$najax.history.listen, $najax.history.replace&lt;/i>'s options.
 * @param {assoc} [opt.data=null] Passed values.
 *
 * @tutorial static-history
 *
 * @example
 * $najax.history.replaceListen(function(e, id, title, data){ ... }, id);
 */
njx.history.replaceListen = function(fn, id, title, opt){
	opt = ext({data: null}, opt);

	njx.history.listen(fn, opt);

	njx.history.replace(null, id, title, opt);
};

/**
 * Get &lt;i>history.state&lt;/i>.
 * @function state
 * @memberof $najax.history
 * @returns {assoc}
 *
 * @tutorial static-history
 *
 * @example
 * vs = $najax.history.state();
 */
njx.history.state = function(){
	return history.state || null;
};
</pre>
    </article>
</section>





		</div>
	</div>

	<div class="clearfix"></div>

	

</div>
</div>

<div class="modal fade" id="searchResults">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">Search results</h4>
      </div>
      <div class="modal-body"></div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div>

<footer>

	&nbsp;


<span class="jsdoc-message">
	Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a>
	
	using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
</footer>

<script src="scripts/docstrap.lib.js"></script>
<script src="scripts/toc.js"></script>
<script type="text/javascript" src="scripts/fulltext-search-ui.js"></script>

<script>
$( function () {
	$( "[id*='$']" ).each( function () {
		var $this = $( this );

		$this.attr( "id", $this.attr( "id" ).replace( "$", "__" ) );
	} );

	$( ".tutorial-section pre, .readme-section pre" ).each( function () {
		var $this = $( this );

		var example = $this.find( "code" );
		exampleText = example.html();
		var lang = /{@lang (.*?)}/.exec( exampleText );
		if ( lang && lang[1] ) {
			exampleText = exampleText.replace( lang[0], "" );
			example.html( exampleText );
			lang = lang[1];
		} else {
			var langClassMatch = example.parent()[0].className.match(/lang\-(\S+)/);
			lang = langClassMatch ? langClassMatch[1] : "javascript";
		}

		if ( lang ) {

			$this
			.addClass( "sunlight-highlight-" + lang )
			.addClass( "linenums" )
			.html( example.html() );

		}
	} );

	Sunlight.highlightAll( {
		lineNumbers : true,
		showMenu : true,
		enableDoclinks : true
	} );

	$.catchAnchorLinks( {
        navbarOffset: 10
	} );
	$( "#toc" ).toc( {
		anchorName  : function ( i, heading, prefix ) {
			var id = $( heading ).attr( "id" );
			return id && id.replace(/\~/g, '-inner-').replace(/\./g, '-static-') || ( prefix + i );
		},
		selectors   : "#toc-content h1,#toc-content h2,#toc-content h3,#toc-content h4",
		showAndHide : false,
		smoothScrolling: true
	} );

	$( "#main span[id^='toc']" ).addClass( "toc-shim" );
	$( '.dropdown-toggle' ).dropdown();

    $( "table" ).each( function () {
      var $this = $( this );
      $this.addClass('table');
    } );

} );
</script>



<!--Navigation and Symbol Display-->


<!--Google Analytics-->


<script type="text/javascript">
	$(document).ready(function() {
		SearcherDisplay.init();
	});
</script>

</body>
</html>
